/* 
 * File:   testorsomething.cpp
 * Author: Satan
 *
 * Created on September 12, 2012, 8:03 PM
 */

#include <windows.h>
#include <GL/glut.h> 

#include "hfgl/hfgl_point.h"
#include "svgloader/svgloader.h"
#include "exceptions/engexeption.h"
#include "sceneobject/sceneobject.h"
#include "hfgl/hfgl_picture.h"

sceneobject scenobj;

void init(void)
{
    //Выбрать фоновый(очищающий) цвет
    glClearColor(0.0,0.0,0.0,0.0);
    
    glClear(GL_COLOR_BUFFER_BIT);
    //Установить проекцию
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
//    glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
    glOrtho(0.0, 800.0, 0.0, 800.0, -1.0, 1.0);    
}

void display(void)
{
    scenobj.draw();

    //Не ждем. Начинаем выполнять буферизованные команды OpenGL 
    glFlush(); 
}

#ifdef __DEBUG
int main(int argc, char **argv)
{
#else
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)  
{
    int argc = 0;
    char *argv = NULL;
#endif
    svgloader *zz = NULL;

    try
    {
        std::string fileName = argc > 1 ? std::string(argv[1]) : "c:\\Work\\Projects\\projhimskforest\\check_projects\\ra_opengl\\pics\\pekaface.svg";
        zz = new svgloader(fileName);
    } catch(engexeption &e)
    {
        MessageBox(NULL, e.getMessage().c_str(), "Error", MB_OK | MB_ICONINFORMATION);
    };
    
    scenobj.setImage(zz);

#ifdef __DEBUG
    glutInit(&argc, argv); 
#else
    glutInit(&argc, &argv); 
#endif

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); 
    glutInitWindowSize(640, 480); 
    glutInitWindowPosition(100,100); 
    glutCreateWindow("hello"); 
    init(); 
    glutDisplayFunc(display); 
    
    glutMainLoop();

    delete zz;
    return 0; 
}